#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<string>
using namespace std;

class Solution {
public:
    int lengthOfLongestSubstring(string s)
    {
        string ret;
        int max = 0;
        int mid = 0;
        for (char x : s)
        {
            for (int i = 0; i < ret.size(); i++)
            {
                if (x == ret[i])
                {
                    max -= (i + 1);
                    ret.erase(0, i + 1);
                    break;
                }
            }
            max++;
            ret.push_back(x);
            mid = max > mid ? max : mid;
        }
        return mid;
    }
};